<?php 
header('content-type:text/html;charset=utf8');
$city = $_POST['city'];
// echo $city;die;
$dsn = "mysql:host=localhost;dbname=month8;charset=utf8";
$pdo = new PDO($dsn,'root','root');
$url = "http://api.k780.com:88/?app=weather.future&weaid=$city&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";

$content = file_get_contents($url);
// var_dump($content);die;
$data = json_decode($content,true);
//print_r($data);die;
$res = $data['result'];

	foreach ($res as $key => $value) {
		# code...
		$city = $value['citynm'];
		$week = $value['week'];
		$temp_high = $value['temp_high'];
		$temp_low = $value['temp_low'];
		$temperature = $value['temperature'];

		$sql = "INSERT INTO weather values ('null','$city','$week','$temp_high','$temp_low','$temperature')";
		$info=$pdo->exec($sql);
	}
	if($info){
		$data = array('code'=>'1','msg'=>'添加成功');
	}else{
		$data = array('code'=>'0','msg'=>'添加失败');
	}
	echo json_encode($data);
 ?>